/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.validation.constraints.NotNull;

/**
 *
 * @author Alberto, Alessandra
 */
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@NamedQueries({
       @NamedQuery(
            name = "findByUserNewNot",
            query = "SELECT n FROM Notification n WHERE n.user = :Nuser AND n.visualized = FALSE"
        ),
        @NamedQuery(
            name = "findByUserNot",
            query = "SELECT n FROM Notification n WHERE n.user = :Nuser"
        )
})

public abstract class Notification implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected Integer id;
    
    @ManyToOne
    @JoinColumn(name = "iduser", referencedColumnName = "id")
    protected User user;
    
    @NotNull(message = "May not be empty")
    protected Boolean visualized;

    public Boolean getVisualized() {
        return visualized;
    }

    public void setVisualized(Boolean visualized) {
        this.visualized = visualized;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
    
    public Notification () {
        
    }

    public Notification(User user) {
        this.user = user;
        this.visualized = Boolean.FALSE;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Notification other = (Notification) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Notification: notification";
    }
    
    
}
